package com.gec.hawaste.mapper;

import com.gec.hawaste.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author gec
 * @since 2022-11-22
 */
public interface SysUserMapper extends BaseMapper<SysUser> {

    @Select("SELECT \n" +
            "su.* \n" +
            "FROM \n" +
            "sys_user_role sur,sys_user su \n" +
            "WHERE \n" +
            "sur.del_flag=0 \n" +
            "AND \n" +
            "su.del_flag=0 \n" +
            "AND \n" +
            "sur.role_id=#{oid} \n" +
            "AND \n" +
            "sur.user_id=su.id")
    List<SysUser> selectUser(Long rid);

    @Select("SELECT \n" +
            "* \n" +
            "FROM \n" +
            "sys_user \n" +
            "WHERE \n" +
            "office_id = #{oid} \n" +
            "AND id NOT IN ( \n" +
            "SELECT \n" +
            "su.id \n" +
            "FROM \n" +
            "sys_user_role sur,\n" +
            "sys_user su \n" +
            "WHERE \n" +
            "sur.del_flag = 0 \n" +
            "AND su.del_flag = 0 \n" +
            "AND sur.role_id = #{rid} \n" +
            "AND sur.user_id = su.id \n" +
            ")")
    List<SysUser> selectNoRole(@Param("rid") Long rid, @Param("oid") Long oid);

}
